<template>
  <div>
    <myheader></myheader>
    <navtable></navtable>
    <b class="line"></b>
    <div class="center" style="margin-top:0;">
      <div class="col-main">
        <div class="main-wrap">

          <div class="user-info">
            <!--标题 -->
            <div class="am-cf am-padding">
              <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">个人资料</strong> / <small>Personal&nbsp;information</small></div>
            </div>
            <hr />

            <!--头像 -->
            <div class="user-infoPic" style="margin-bottom:15px">
              <div class="filePic">
                <input type="text" class="inputPic" id="replaceImg" allowexts="gif,jpeg,jpg,png,bmp" accept="image/*">
                <img class="am-circle am-img-thumbnail" id="userImg" v-bind:src="user.userlogo" alt="点击上传头像" />
              </div>

              <p class="am-form-help">头像</p>

              <div class="info-m">
                <div><b>用户名：<i>{{user.nickname}}</i></b></div>
              </div>
            </div>

            <!--个人信息 -->
            <div class="info-main">
              <form class="am-form am-form-horizontal">

                <div class="am-form-group">
                  <label for="user-name2" class="am-form-label">昵称</label>
                  <div class="am-form-content">
                    <input type="text" id="user-name2" v-model="user.nickname" placeholder="nickname">

                  </div>
                </div>
                <div class="am-form-group">
                  <label class="am-form-label">性别</label>
                  <div class="am-form-content sex">
                    <label class="am-radio-inline">
                      <input type="radio" name="radio10" v-model="user.sex" value="男" data-am-ucheck> 男
                    </label>
                    <label class="am-radio-inline">
                      <input type="radio" name="radio10" value="女" v-model="user.sex" data-am-ucheck> 女
                    </label>
                    <label class="am-radio-inline">
                      <input type="radio" name="radio10" value="保密" v-model="user.sex" data-am-ucheck> 保密
                    </label>
                  </div>
                </div>

                <div class="am-form-group">
                  <label for="user-birth" class="am-form-label">生日</label>
                  <div class="am-form-content">
                    <el-date-picker v-model="user.birth" type="date" placeholder="选择日期">
                    </el-date-picker>
                  </div>

                </div>
                <div class="info-btn">
                  <div class="am-btn am-btn-danger" v-on:click="saveUser()">保存修改</div>
                </div>

              </form>
            </div>

          </div>

        </div>
        <!--底部-->

        <foot></foot>
      </div>
      <leftmenu></leftmenu>
      <!--左侧菜单导航栏 begin-->
      <navfull></navfull>
      <!--左侧菜单导航栏 end-->
    </div>
  </div>
</template>

<script>
import myheader from '@/components/myheader.vue'
import navfull from '@/components/navfull.vue'
import foot from '@/components/foot.vue'
import leftmenu from '@/components/leftmenu.vue'
import navtable from '@/components/navtable.vue'
import myUpload from 'vue-image-crop-upload/upload-1.vue'
export default {
  name: 'user',
  data () {
    return {
      user: {
        userId: "12",
        userlogo: "11",
        account: "",
        nickname: "",
        truename: "",
        sex: "女",
        birth: "",
        phone: "",
        email: ""
      },
      show: true,
      params: {
        token: '123456798',
        name: 'avatar'
      },
      headers: {
        smail: '*_~'
      },
      imgDataUrl: '' // the datebase64 url of created image
    }
  },
  components: {
    myheader,
    navfull,
    foot,
    leftmenu,
    navtable,
    'my-upload': myUpload
  },
  mounted () {
    this.loadUser();
  },
  methods: {
    toggleShow () {
      this.show = !this.show;
    },
    loadUser () {
      this.axios.get("/user/user", {
        params: {
          userId: 12
        }
      })
        .then((response) => {
          var result = response.data;
          if (result.code == 400) {
            return;
          }
          var userModel = result.data;
          var user = {}
          user.userlogo = userModel.userlogo;
          user.account = userModel.account;
          user.nickname = userModel.nickname;
          user.truename = userModel.truename;
          user.sex = userModel.sex;
          user.birth = userModel.birth;
          user.phone = userModel.phone;
          user.email = userModel.email;
          user.userId = userModel.userId;
          this.user = user;
        })

    },
    saveUser () {
      var user = this.user;
      this.axios.put("user/user",
        user
      )
        .then((response) => {
          var result = response.data;
          if (result.code == 200) {
            this.$layer.msg("保存成功");
            this.loadUser();
          }
        })
    },
    dateFormatter (date) {
      var time = new Date(date);
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
    },
  }
}
function add0 (m) {
  return m < 10 ? '0' + m : m
}
</script>

<style scoped>
@import "../../../AmazeUI-2.4.2/assets/css/admin.css";
@import "../../../AmazeUI-2.4.2/assets/css/amazeui.css";
@import "../../../assets/css/personal.css";
@import "../../../assets/css/infstyle.css";
</style>
